unit Form2;

{$mode ObjFPC}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, LCLType, ComCtrls, StdCtrls, Windows;

type

  { TForm2 }

  TForm2 = class(TForm)
    Button1: TButton;
    ListView1: TListView;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure ListView1Deletion(Sender: TObject; Item: TListItem);
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
  private

  public

  end;

var
  oForm2: TForm2;

implementation

{$R *.lfm}

{ TForm2 }

procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
  begin
    self.Close;
  end;
end;

procedure TForm2.ListView1Deletion(Sender: TObject; Item: TListItem);
begin
  OutputDebugString(pchar('Deleting ' + Item.Caption));
end;

procedure TForm2.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
var
  s: string;
begin
  if selected then s := 'selected' else s := 'unselected';
  OutputDebugString(pchar(Format('%s %s', [Item.Caption, s])));
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  ListView1.Items.Clear;
end;

procedure TForm2.FormCreate(Sender: TObject);
var
  i: integer;
  item: TListItem;
begin
  for i := 0 to 100 do
  begin
    item := ListView1.Items.Add;
    item.Caption := Format('Item%d', [i]);
  end;
end;

end.

